<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>SharedArrayBuffer</title>
</head>
<body>
  <script>
    const worker = new Worker('./27_2_10_3_worker.js');

    // 创建 1 字节缓冲区
    const sharedArrayBuffer = new SharedArrayBuffer(1);

    // 创建 1 字节缓冲区的视图
    const view = new Uint8Array(sharedArrayBuffer);

    // 父上下文赋值 1
    view[0] = 1;

    worker.onmessage = () => {
      console.log(`buffer value after worker modification: ${view[0]}`);
    };

    // 发送对 sharedArrayBuffer 的引用
    worker.postMessage(sharedArrayBuffer);
    // buffer value before worker modification: 1
    // buffer value after worker modification: 2
  </script>
</body>
</html>